<%@page import="de.hsmannheim.pepa.patientenportal.apanwep.logic.Tables"%>
<%@page import="de.hsmannheim.pepa.patientenportal.apanwep.model.contact"%>
<%@page import="java.util.List"%>
<%@page import="de.hsmannheim.pepa.patientenportal.apanwep.logic.Outcome"%>
<%@page import="java.util.LinkedList"%>

<%
	LinkedList<Outcome> list = (LinkedList<Outcome>) request.getAttribute("data");
	Tables t = new Tables();
	List<contact> liste = t.getAllContact();
	for(int i = 1; i <list.size(); i++){
		if(list.get(i - 1).getMessageId() == list.get(i).getMessageId()){
			list.get(i - 1).setUsername(list.get(i - 1).getUsername()+", "+list.get(i).getUsername());
			list.remove(i);
		}
	}
%>

<script type="text/javascript">
$(document).ready(function () {
	var responsiveHelpers;
	var breakpointDefinition = {
	    tablet: 1024,
	    phone : 480,
	};
	var table = $('#result');
	table.dataTable({
		"bFilter":true,
	    autoWidth        : false,
	    preDrawCallback: function () {
	        // Initialize the responsive datatables helper once.
	        if (!responsiveHelpers) {
	            responsiveHelpers = new ResponsiveDatatablesHelper(table, breakpointDefinition);
	        }
	    },
	    rowCallback    : function (nRow) {
	    	responsiveHelpers.createExpandIcon(nRow);
	    },
	    drawCallback   : function (oSettings) {
	    	responsiveHelpers.respond();
	    }

			

		});	
		});

</script>

<table id="result" class="table table-bordered table-striped" >
	<thead>
		<tr>
			<th data-class="expand">MessageID</th>
			<th >DateTime</th>
			<th data-hide="phone, tablet" data-name="eventactioncode">Event-action</th>
			<th data-hide="phone, tablet" data-name="username">Username</th>
			<th data-hide="phone, tablet" data-name="participant">Name of Document</th>
		</tr>
	</thead>

	<tbody>
		<%
			Outcome outcome = new Outcome();
			String eventAction = "";
			for(int i = 0; i <list.size(); i++){
				if(list.get(i).getEventAction().equals("C"))
					eventAction = "Create";
				else if(list.get(i).getEventAction().equals("R"))
					eventAction = "Read/View/Print/Query";
				else if(list.get(i).getEventAction().equals("U"))
					eventAction = "Update";
				else if(list.get(i).getEventAction().equals("D"))
					eventAction = "Delete";
				else if(list.get(i).getEventAction().equals("E")){
					eventAction = "Execute";
				}
		%>
		<tr
		<%
		for(int j = 0; j < liste.size(); j++){
			if(list.get(i).getMessageId() == liste.get(j).getMessage_id()){
		%>	
				style="color:#8FBC8F;"
		<%
			}
		}
		%>		
			title="Double click to take contact with the security officertragter kontaktieren!"
			ondblclick="loadData('<%=list.get(i).getMessageId()%>','<%=list.get(i).getUsername()%>')">
			<td><%=list.get(i).getMessageId()%></td>
			<td><%=list.get(i).getEventDateTime()%></td>
			<td><%=eventAction%></td>
			<td><%=list.get(i).getUsername()%></td>
			<td><%=list.get(i).getObjectName()%></td>
		</tr>
		<%
			}
		%>
	</tbody>
</table>

<script>

function loadData(msgId, username) {	
	document.getElementById('schutzerMContainer').style.backgroundColor = "#028AC2";
	document.getElementById('searchMContainer').style.backgroundColor = "#E4E4E4";
	document.getElementById('datenschutzbeauftragterMenu').style.display = 'block';
	document.getElementById('datenschutzbeauftragterMenu').style.visibility = 'visible';
	document.getElementById('datenZugangMenu').style.display = 'none';
	document.getElementById('datenZugangMenu').style.visibility = 'hidden';
	transData(msgId, username);
}
	
</script>
